<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="en">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css">


  <meta name="keywords" content="Hexo, NexT">





  <link rel="alternate" href="/atom.xml" title="Hero's notebooks" type="application/atom+xml">




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2">






<meta name="description" content="hero&apos;s notebooks">
<meta property="og:type" content="website">
<meta property="og:title" content="Hero&#39;s notebooks">
<meta property="og:url" content="https://chenzk1.github.io/index.html">
<meta property="og:site_name" content="Hero&#39;s notebooks">
<meta property="og:description" content="hero&apos;s notebooks">
<meta property="og:locale" content="en">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Hero&#39;s notebooks">
<meta name="twitter:description" content="hero&apos;s notebooks">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://chenzk1.github.io/">





  <title>Hero's notebooks</title>
  














</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  
  
    
  

  <div class="container sidebar-position-left 
   page-home 
 ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Hero's notebooks</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Sometimes naive.</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            Categories
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="Searching..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
  <section id="posts" class="posts-expand">
    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/20/面试真题整理/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/20/面试真题整理/" itemprop="url">面试真题整理</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-20T21:03:53+08:00">
                2019-11-20
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="pinkman"><a href="#pinkman" class="headerlink" title="pinkman"></a>pinkman</h1><h2 id="字节跳动"><a href="#字节跳动" class="headerlink" title="字节跳动"></a>字节跳动</h2><ul>
<li>大数相乘</li>
<li>不同字符最大子串</li>
</ul>
<h2 id="滴滴搜索"><a href="#滴滴搜索" class="headerlink" title="滴滴搜索"></a>滴滴搜索</h2><ul>
<li>链表相加（两数相加II）</li>
<li>输出二叉树的所有路径</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/链表-LRU/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/链表-LRU/" itemprop="url">链表-LRU</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T19:46:45+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h2 id="链表"><a href="#链表" class="headerlink" title="链表"></a>链表</h2><ul>
<li>单链表</li>
<li>双链表<ul>
<li>占用更多空间，但提高了灵活性</li>
<li>例如删除某个指针指向的节点，单链表需要遍历以找到上一个节点，而双链表则不需要、</li>
<li>在某个节点前插入一个节点，O(1)</li>
</ul>
</li>
<li>循环链表</li>
<li>双向循环链表</li>
</ul>
<h2 id="链表与数组"><a href="#链表与数组" class="headerlink" title="链表与数组"></a>链表与数组</h2><ul>
<li>数组的存储空间连续：插入、删除时需要移动大量数据，时间复杂度为O(n)；查找数据O(1)</li>
<li>链表的存储空间不连续：插入、删除只需要O(1)；查找数据O(n)</li>
<li>链表扩容灵活，而数组大小固定，声明时就需要占用连续的内存空间</li>
<li>链表所需内存更大</li>
<li>链表的一个典型应用场景：LRU缓存</li>
</ul>
<h2 id="链表题目"><a href="#链表题目" class="headerlink" title="链表题目"></a>链表题目</h2><ul>
<li>迭代时注意分解每次迭代所做的事情，注意每次从最底的迭代往上回退时，当前迭代的链表节点与下一节点的指针关系没变</li>
<li>警惕指针丢失，注意操作顺序</li>
<li>利用哨兵简化操作</li>
<li>边界条件<ul>
<li>空链表</li>
<li>只包含一个节点</li>
<li>只包含两个节点</li>
<li>处理头结点和尾结点时</li>
</ul>
</li>
</ul>
<h2 id="LRU缓存"><a href="#LRU缓存" class="headerlink" title="LRU缓存"></a>LRU缓存</h2><p>常见的缓存淘汰策略有：FIFO(first in first out)、LRU(least recently used)、LFU(least frequently used)</p>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/稀疏编码/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/稀疏编码/" itemprop="url">稀疏编码</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ol>
<li><p>稀疏表示</p>
<ul>
<li><p>稀疏：p的维度较大，且尽可能使α中的系数多为0（只有少数的non-zero elements）</p>
</li>
<li><p>作用：</p>
<p>1）拥有更强大表达能力(Representation Power）（去掉冗余的信息）</p>
<p>2）拥有识别和约束能力（Discriminative, or Regularization Power）（加速运算，减小存储（可以通过一些表达方式来表达稀疏矩阵））</p>
</li>
<li><p>用途：</p>
<p>1）信号处理领域：自然界中的信号低频居多，高频基本都是噪声。因此在做基矩阵时，表达系数只在少数低频基上较大，高频基的系数基本都接近于0.所以在一些问题，例如逆问题中，从一些损坏或者噪声中提取某个信号，相当于解不定方程，不加约束的话会有很多可行解。于是在解决这类问题的时候，会加上约束，即稀疏性约束</p>
<p>2）推荐系统：用户行为，例如用户评价是一个低秩矩阵</p>
<p>3）深度学习：l1正则抗拟合</p>
</li>
<li><p>表示：如下图，原来的特征为x，编码后为α。相当于某向量在基下的坐标。</p>
</li>
</ul>
<p><img src="https://img-blog.csdn.net/20151223214504471" alt></p>
</li>
</ol>
<ul>
<li><p>实现：</p>
<p>使得表示前后误差尽可能小：<br>$$<br>J(D, α)=|D α-x|<em>{2}<br>$$<br>加入限制条件——稀疏：<br>$$<br>J(D, α)=|D α-x|</em>{2}+\lambda|α|_{1}<br>$$</p>
</li>
<li><p>理解：</p>
<p>1）有点像l1正则化</p>
<p>2）降维是原向量空间的子集，稀疏是原向量空间子集的集合</p>
</li>
</ul>
<ol start="2">
<li><p>非NN中特征稀疏的解决</p>
<p>1）推荐系统FM模型解决</p>
<p>2）</p>
</li>
</ol>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/推荐系统实验方法与评测/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/推荐系统实验方法与评测/" itemprop="url">推荐系统实验方法与评测</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="实验方法"><a href="#实验方法" class="headerlink" title="实验方法"></a>实验方法</h1><h2 id="离线"><a href="#离线" class="headerlink" title="离线"></a>离线</h2><p>训练集、测试集</p>
<table>
<thead>
<tr>
<th>优点</th>
<th>缺点</th>
</tr>
</thead>
<tbody>
<tr>
<td>不需要对实际系统的控制</td>
<td>无法计算商业上关心的指标</td>
</tr>
<tr>
<td>无需用户参与实验</td>
<td>离线与在线的差距</td>
</tr>
<tr>
<td>速度快，可以测试大量算法</td>
</tr>
</tbody>
</table>
<h2 id="用户调查"><a href="#用户调查" class="headerlink" title="用户调查"></a>用户调查</h2><table>
<thead>
<tr>
<th>优点</th>
<th>缺点</th>
</tr>
</thead>
<tbody>
<tr>
<td>可以获得体现主观感受的指标</td>
<td>招募测试用户代价大</td>
</tr>
<tr>
<td>相对在线实验风险低</td>
<td>难以组织大量用户</td>
</tr>
</tbody>
</table>
<h2 id="在线"><a href="#在线" class="headerlink" title="在线"></a>在线</h2><p>ABtest</p>
<h1 id="评测指标"><a href="#评测指标" class="headerlink" title="评测指标"></a>评测指标</h1><ul>
<li><p>用户满意度</p>
<p>用户调查 / 在线实验</p>
</li>
<li><p>准确度</p>
<ul>
<li><p>评分预测: rmse, mae</p>
</li>
<li><p>Top N: recall, precision<br>$$<br>\begin{array}{l}{\quad \text { Recall }=\frac{\sum_{u v}|R(u) \cap T(u)|}{\sum_{u=U}|T(u)|}} \ {\text { Precision }=\frac{\sum_{u v}|R(u) \cap T(u)|}{\sum_{u=v}|R(u)|}}\end{array}<br>$$</p>
</li>
</ul>
</li>
<li><p>覆盖率：需体现推荐系统挖掘长尾的能力</p>
<ul>
<li><p>信息熵 H = - sigma p(i)logp(i)</p>
</li>
<li><p>基尼系数<br>$$<br>G=\frac{1}{n-1} \sum_{j=1}^{n}(2 j-n-1) p\left(i_{j}\right)<br>$$<br>这里ij是按照物品流行度p()从小到大排序的物品列表中第j个物品</p>
<p><img src="/Users/didi/Library/Application Support/typora-user-images/image-20190924155235973.png" alt="image-20190924155235973"></p>
</li>
</ul>
</li>
<li><p>多样性：用户兴趣是广泛的</p>
</li>
<li>新颖性：给用户推荐其之前没有听过或看过的物品</li>
<li>精细度：推荐结果和用户的历史兴趣不相似，但却让用户觉得满意，那么就可以说推荐结果的惊喜度很高，而推荐的新颖性仅仅取决于用户是否听说过这个 推荐结果。</li>
<li>信任度<ul>
<li>提高推荐系统透明度</li>
<li>考虑用户社交网络信息，利用好友信息给用户作推荐，并用好友进行推荐解释</li>
</ul>
</li>
<li>实时性：物品的时效性、用户兴趣的时效性</li>
<li>健壮性（鲁棒性）：反作弊</li>
<li>商业目标</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/推荐系统FM、FFM/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/推荐系统FM、FFM/" itemprop="url">推荐系统FM/FMM</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <p>CTR预估时，除了单特征，还要对特征进行组合。组合方法：FM系列和Tree系列。</p>
<ol>
<li><p>FM：为了解决特征稀疏</p>
<p>one-hot编码后，特征空间非常稀疏，进而造成一些问题。</p>
</li>
<li><p>线性模型：<br>$$<br>y=\omega_{0}+\sum_{i=1}^{n} \omega_{i} x_{i}<br>$$</p>
</li>
<li><p>FM：加入线性组合，只加入两个特征的组合：</p>
</li>
</ol>
<p>$$<br>y=\omega_{0}+\sum_{i=1}^{n} \omega_{i} x_{i}+\sum_{i=1}^{n-1} \sum_{j=i+1}^{n} \omega_{i j} x_{i} x_{j}<br>$$</p>
<pre><code>- 问题：特征稀疏，xi, xj都不为0的情况比较少，所以wij无法训练得出
</code></pre><ul>
<li><p>解法：</p>
<ul>
<li>共n个特征，对每个特征分量xi引入辅助向量Vi，Vi的长度为k<br>$$<br>\mathbf{V}=\left(\begin{array}{cccc}{v_{11}} &amp; {v_{12}} &amp; {\cdots} &amp; {v_{1 k}} \ {v_{21}} &amp; {v_{22}} &amp; {\cdots} &amp; {v_{2 k}} \ {\vdots} &amp; {\vdots} &amp; {} &amp; {\vdots} \ {v_{n 1}} &amp; {v_{n 2}} &amp; {\cdots} &amp; {v_{n k}}\end{array}\right)<em>{n \times k}=\left(\begin{array}{c}{\mathbf{v}</em>{1}} \ {\mathbf{v}<em>{2}} \ {\vdots} \ {\mathbf{v}</em>{n}}\end{array}\right)<br>$$<br>有：<br>$$<br>\hat{\mathbf{W}}=\mathbf{V} \mathbf{V}^{T}=\left(\begin{array}{c}{\mathbf{v}<em>{1}} \ {\mathbf{v}</em>{2}} \ {\vdots} \ {\mathbf{v}<em>{n}}\end{array}\right)\left(\begin{array}{cccc}{\mathbf{v}</em>{1}} \ {\mathbf{v}<em>{1}^{T}} &amp; {\mathbf{v}</em>{2}^{T}} &amp; {\cdots} &amp; {\left.\mathbf{v}<em>{n}^{T}\right)} \ {\mathbf{v}</em>{n}} &amp; {} &amp; {} &amp; {}\end{array}\right.<br>$$<br>从求解w变为求解v：<br>$$<br>\begin{aligned} &amp; \sum_{i=1}^{n-1} \sum_{j=i+1}^{n}\left\langle\mathbf{v}<em>{i}, \mathbf{v}</em>{j}\right\rangle x_{i} x_{j} \=&amp; \frac{1}{2} \sum_{i=1}^{n} \sum_{j=i+1}^{n}\left\langle\mathbf{v}<em>{i}, \mathbf{v}</em>{j}\right\rangle x_{i} x_{j}-\frac{1}{2} \sum_{i=1}^{n}\left\langle\mathbf{v}<em>{i}, \mathbf{v}</em>{i}\right\rangle x_{i} x_{i} \=&amp; \frac{1}{2}\left(\sum_{i=1}^{n} \sum_{j=1}^{n}\left\langle\mathbf{v}<em>{i}, \mathbf{v}</em>{j, f}, x_{i} x_{j}-\sum_{i=1}^{n} \sum_{f=1}^{k} v_{i, f} v_{i, f} x_{i} x_{i}\right)\right.\=&amp; \frac{1}{2} \sum_{f=1}^{k}\left(\left(\sum_{i=1}^{n} v_{i, f} x_{i}\right)^{2}-\sum_{i=1}^{n} v_{i, f}^{2} x_{i}^{2}\right) \=&amp; \frac{1}{2} \sum_{f=1}^{k}\left(\left(\sum_{i=1}^{n} v_{i, f} x_{i}\right)^{2}-\sum_{i=1}^{n} v_{i, f}^{2} x_{i}^{2}\right) \end{aligned}<br>$$<br>即：从求ab变为求解<br>$$<br>\left((a+b+c)^{2}-a^{2}-b^{2}-c^{2}\right.<br>$$</li>
</ul>
</li>
</ul>
<ol start="4">
<li><p>FFM</p>
<ul>
<li><p>加入field的概念：FM中，v针对特征是经过one-hot后处理后的，有些特征是从同一个类别特征one-hot得来的</p>
</li>
<li><p>隐向量不仅与特征有关，也与field有关</p>
</li>
<li><p>n个特征属于f个field，FM相当于把所有特征归属于一个field时的FFM。</p>
</li>
<li><p>FFM有nfk个参数，FM有nk个</p>
</li>
<li><p>$$<br>y(\mathbf{x})=w_{0}+\sum_{i=1}^{n} w_{i} x_{i}+\sum_{i=1}^{n} \sum_{j=i+1}^{n}\left\langle\mathbf{v}_{i ,f_j}, \mathbf{v}<em>{j ,f</em>{i}}\right\rangle x_{i} x_{j}<br>$$</p>
</li>
<li><p>一种实现：将问题定义为分类问题，使用加入正则项的logloss（1，-1的logloss）<br>$$<br>\min <em>{\mathbf{w}} \sum</em>{i=1}^{L} \log \left(1+\exp \left{-y_{i} \phi\left(\mathbf{w}, \mathbf{x}_{i}\right)\right}\right)+\frac{\lambda}{2}|\mathbf{w}|^{2}<br>$$<br>利用SGD进行训练。</p>
</li>
</ul>
</li>
</ol>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/梯度下降及其优化算法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/梯度下降及其优化算法/" itemprop="url">梯度下降及其优化算法</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="GD及其变体"><a href="#GD及其变体" class="headerlink" title="GD及其变体"></a>GD及其变体</h1><h2 id="Batch-GD-Vanilla-GD"><a href="#Batch-GD-Vanilla-GD" class="headerlink" title="Batch GD / Vanilla GD"></a>Batch GD / Vanilla GD</h2><p><img src="https://www.zhihu.com/equation?tex=%5Ctheta_%7Bi%2B1%7D%3D+%5Ctheta_t+-+%5Ceta+g_t" alt></p>
<p>ALL SAMPLES</p>
<h2 id="SGD"><a href="#SGD" class="headerlink" title="SGD"></a>SGD</h2><p>求梯度的时候，要经过所有样本，计算量会很大，随机梯度下降是<strong>每次迭代随机选取</strong>一个样本计算梯度。</p>
<p>每次用到的梯度方差大，收敛过程不稳定</p>
<p>问题是可能到不了局部最优。</p>
<h2 id="mini-batch-gd"><a href="#mini-batch-gd" class="headerlink" title="mini-batch gd"></a>mini-batch gd</h2><p>降低了更新参数的方差，收敛过程更稳定</p>
<h1 id="优化算法"><a href="#优化算法" class="headerlink" title="优化算法"></a>优化算法</h1><h2 id="Momentum"><a href="#Momentum" class="headerlink" title="Momentum"></a>Momentum</h2><h3 id="指数加权平均"><a href="#指数加权平均" class="headerlink" title="指数加权平均"></a>指数加权平均</h3><p>$$<br>v_{t}=\beta v_{t-1}+(1-\beta) \theta_{t}<br>$$<br>$$<br>\begin{array}{l}{v_{0}=0} \ {v_{1}=\beta v_{0}+(1-\beta) \theta_{1}} \ {v_{2}=\beta v_{1}+(1-\beta) \theta_{2}=\beta\left(\beta v_{0}+\theta_{1}\right)+(1-\beta) \theta_{2}} \ {\vdots} \ {v_{t}=\beta v_{t-1}+(1-\beta) \theta_{t}=\sum_{i=1}^{t} \beta^{t-i}(1-\beta) \theta_{t}}\end{array}<br>$$</p>
<ul>
<li>使用之前的观测值以及当前观测值的平均来作为所需要的值，以达到平滑的目的。距离当前时刻越近的观测值对求得移动平均值的影响越大。</li>
<li>指数的意思是：按照公式归纳，之前观测值的权值为设定常数的次方。</li>
</ul>
<h3 id="动量梯度下降"><a href="#动量梯度下降" class="headerlink" title="动量梯度下降"></a>动量梯度下降</h3><p>$$<br>\begin{aligned} v_{t} &amp;=\beta v_{t-1}+(1-\beta) \nabla J(\theta)<em>{t} \ \theta &amp;=\theta-\alpha v</em>{t} \end{aligned}<br>$$<br>也即：<br>$$<br>\begin{aligned} v_{t} &amp;=\gamma v_{t-1}+\eta \nabla J(\theta)<em>{t} \ \theta &amp;=\theta-v</em>{t} \end{aligned}<br>$$</p>
<ul>
<li>动量梯度下降即对梯度进行指数加权平均，以达到平滑的作用，利用到了历史梯度值。</li>
<li>平滑：例如对于有些参数梯度正负不断震荡，导致loss也在这些参数对应的方向上不断震荡，那加入历史值则会在一定程度上抵消震荡；而如果某些参数的变化是一致的，平均后不会产生太大影响，只是使得具体值变化变小了而已。</li>
</ul>
<h2 id="Nesterov-Accelerated-Gradient-NAG"><a href="#Nesterov-Accelerated-Gradient-NAG" class="headerlink" title="Nesterov Accelerated Gradient,NAG"></a>Nesterov Accelerated Gradient,NAG</h2><ul>
<li>之前的方法是利用梯度方向来进行参数更新，Nesterov对梯度加入了预测功能：即预测参数未来的近似位置，并利用此位置处的参数梯度来进行更新当前参数</li>
</ul>
<p>$$<br>\begin{aligned} v_{t} &amp;=\gamma v_{t-1}+\eta \nabla J\left(\theta-\gamma v_{t-1}\right) \ \theta &amp;=\theta-v_{t} \end{aligned}<br>$$<br><img src="https://img2018.cnblogs.com/blog/439761/201903/439761-20190313101736137-755682989.jpg" alt></p>
<ul>
<li>动量下降为蓝色，短蓝为当前梯度，常蓝为动量；NAG为，先在之前的动量项（棕色）前进一步，并计算此时的梯度，然后用这个梯度与之前的动量项指数平均。</li>
<li>相当于先判断下一阶段可能要去的地方，然后使用那个地方的梯度，相当于提前预测，做个修正，少走冤枉路。</li>
</ul>
<h2 id="Adagrad-Adaptive-Gradient"><a href="#Adagrad-Adaptive-Gradient" class="headerlink" title="Adagrad(Adaptive Gradient)"></a>Adagrad(Adaptive Gradient)</h2><ul>
<li>之前的参数更新时，不同的参数使用相同的步长，为了对不同的参数使用不同的步长，引入Adagrad，当梯度大时，步长小，梯度小时，步长大。</li>
<li>AdaGrad对每个变量更新时，利用该变量历史积累的梯度来修正其学习速率。这样，已经下降的很多的变量则会有小的学习率，而下降较少的变量则仍然保持较大的学习率。<br>$$<br>\theta_{(t+1, i)}=\theta_{(t, i)}-\frac{\eta}{\sqrt{\sum_{\tau=1}^{t} \nabla J\left(\theta_{i}\right)<em>{\tau}+\epsilon}} \cdot \nabla J\left(\theta</em>{i}\right)_{t+1}<br>$$</li>
<li>缺点：<ul>
<li>仍然需要设初始学习率；</li>
<li>学习率不断衰减，到后期会很小，导致训练过早停止。</li>
</ul>
</li>
</ul>
<h2 id="RMSprop"><a href="#RMSprop" class="headerlink" title="RMSprop"></a>RMSprop</h2><p>解决Adagrad学习率衰减的问题</p>
<ul>
<li>学习率衰减：引入动量（指数加权平均），引入超参γ，在累积梯度的<strong>平方</strong>项近似衰减：</li>
</ul>
<p>$$<br>\begin{array}{l}{s_{(t, i)}=\gamma s_{(t-1, i)}+(1-\gamma) \nabla J\left(\theta_{i}\right)<em>{t} \odot \nabla J\left(\theta</em>{i}\right)<em>{t}} \ {\theta</em>{(t, i)}=\theta_{(t-1, i)}-\frac{\eta}{\sqrt{s_{(t, i)}+\epsilon}} \odot \nabla J\left(\theta_{i}\right)_{t}}\end{array}<br>$$</p>
<h2 id="Adam"><a href="#Adam" class="headerlink" title="Adam"></a>Adam</h2><p><strong>RMSprop+Momentum</strong></p>
<p>即梯度的指数平均和梯度平方的指数平均的结合：<br>$$<br>\begin{aligned} m_{t} &amp;=\beta_{1} m_{t-1}+\left(1-\beta_{1}\right) g_{t} \ v_{t} &amp;=\beta_{2} v_{t-1}+\left(1-\beta_{2}\right) g_{t}^{2} \end{aligned}<br>$$<br>mt和vt的初始值为0，训练初期可能较小，因此需要对其放大：<br>$$<br>\begin{aligned} \hat{m}<em>{t} &amp;=\frac{m</em>{t}}{1-\beta_{1}^{t}} \ \hat{v}<em>{t} &amp;=\frac{v</em>{t}}{1-\beta_{2}^{t}} \end{aligned}<br>$$<br>即：<br>$$<br>\theta_{t+1}=\theta_{t}-\frac{\eta}{\sqrt{\hat{v}<em>{t}}+\epsilon} \hat{m}</em>{t}<br>$$<br>作者建议β1设置为0.9,β2设置为0.999，取ϵ=10−8。</p>
<h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><ul>
<li>从Vanilla GD到动量项，解决了梯度震荡的问题；<strong>Momentum</strong></li>
<li>加入历史梯度累计作为修正项，解决了每个参数的步长一样的问题；<strong>Adagrad</strong></li>
<li>一阶梯度累计项变二阶梯度累计项的指数加权平均，解决了Adagrad训练后期学习率小的问题；<strong>RMSprop</strong></li>
<li><strong>Momentum+RMSprop=Adam</strong></li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/滴滴实习总结/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/滴滴实习总结/" itemprop="url">滴滴实习总结</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h1 id="信用分"><a href="#信用分" class="headerlink" title="信用分"></a>信用分</h1><h2 id="背景"><a href="#背景" class="headerlink" title="背景"></a>背景</h2><p>平台上每天对乘客有10+w差评投诉，专快<strong>坏账</strong>每月3千万，<strong>司机nps -17%</strong>，<strong>乘客诈骗</strong>引起pr事件，专车乘客封禁但依然能活跃在其他业务线等，乘客管控一片空白，业务迫切希望有一个抓手来解决这些问题。在这个背景下，乘客行为分应运而生。</p>
<p>乘客行为分的本质是<strong>按照乘客在平台上的行为对其进行分层</strong>。乘客行为分是构建良好司机／乘客生态的一部分，<strong>能为平台提供更多GMV／运力，为司机提供更好体验（NPS）</strong>，为乘客提供更好体验（NPS）。</p>
<ul>
<li>平台资损：补券、有责取消（取消费用、取消次数、取消率）</li>
<li>平台体验：司机投诉（司机nps）、乘客投诉（虚假投诉）</li>
</ul>
<p>定位：<strong>乘客行为分是连接B端和C端的工具。其中，C端是乘客，公司内的B端主要包括客服部门 （乘客管控方向）／乘客补贴部门（补贴方向）和乘客运营部门（拉新方向）。</strong></p>
<p>价值：<strong>乘客行为分的核心价值在于为B端提供用户分层服务，为C端提供用户权益（差异化服务）。</strong></p>
<h2 id="应用"><a href="#应用" class="headerlink" title="应用"></a>应用</h2><ul>
<li>准入（乘客运营）：<ul>
<li>乘客行为分替代芝麻分作为海棠湾（出行单车事业部）和黑马（电单车）的准入条件，分别提高<strong>31%</strong>、<strong>30%</strong>的转化率</li>
</ul>
</li>
<li>免押（乘客运营）：<ul>
<li>粤港车减低未播率 提高乘客体验</li>
</ul>
</li>
<li>降资损（乘客管控）：<ul>
<li>恶意补券</li>
<li>低信用乘客不给预付</li>
</ul>
</li>
<li>乘客管控与乘客教育：<ul>
<li>海棠湾和黑马 行为分露出，坏行为下降，好行为上升</li>
<li>深圳地区乘客教育与乘客管控</li>
</ul>
</li>
<li><strong>司机体验优化（低信用乘客豁免）</strong></li>
<li>分单倾斜</li>
<li>用作其他业务的参考依据：为滴滴金融等借贷业务提供决策的依据</li>
</ul>
<h2 id="评估"><a href="#评估" class="headerlink" title="评估"></a>评估</h2><p><img src="C:\Users\Chenzk\Documents\Learning\滴滴\cmd\image\image2019-8-2_11-47-48.png" alt="image2019-8-2_11-47-48"></p>
<p>收益评估：正向收益与负向收益</p>
<h2 id="方案"><a href="#方案" class="headerlink" title="方案"></a>方案</h2><p>履约表现、行为健康度、净贡献值、身份特征</p>
<h3 id="履约表现"><a href="#履约表现" class="headerlink" title="履约表现"></a>履约表现</h3><ul>
<li>标签：表现期内是否违约（网约车业务逾期30天（平台对坏账的定义）以上，滴水贷违约）</li>
<li>特征：履约能力（固定资产、流动资产、平台流水（发单次数、gmv、完单次数））和信用历史（个人借贷还款、逾期（逾期支付次数、逾期支付金额、滴水贷还款总金额、当前逾期未还本金、逾期次数、历史最大逾期天数）等情况的统计信息）</li>
<li>baseline：网约车规则、粤港车规则</li>
<li>样本<ul>
<li>观察期内有行为的乘客，没有行为发生给默认分</li>
<li>抽样：全量粤港车（1万）+全量滴水贷（45万）+随机抽样网约车（ 200万）</li>
</ul>
</li>
<li>分箱<ul>
<li>等频、等距、卡方</li>
</ul>
</li>
<li>模型：见卡方分布及卡方检验、评分卡</li>
<li>评估：（大盘抽样或整个大盘，例如ks、gini等可以直接用整个大盘数据）（如果不合常理问题一般是woc值的分布规律不正常）<ul>
<li>准召（固定一个调整另一个，注重于精确率，粤港车注重于召回率（因为未付订单较少，则降资损更重要，所以查全））、f1、ks（0.42）、auc（0.82）</li>
<li>分布：平滑 正态 有无异常值，如突出的毛刺（对应了分箱或者数据中的异常值，例如企业支付、代叫号，如果企业支付是按乘客算的，那就算看起来是异常数据也要加入）</li>
<li>分数与GMV、坏账、未播率、逾期单数、渗透率、滴水贷逾期金额、滴水贷逾期次数的分布</li>
<li>应用于业务时的影响面、未播率、资损delta</li>
</ul>
</li>
<li>思考：<ul>
<li>label选择的方案：逾期31天和逾期29天在特征方面差别很小，如何设计？考虑去除灰色部分，即训练时只选取逾期25天以内的作为label=0，35天以上作为label=1，但测试的时候全部加入，特征和测试的label不变，依然为30天，即只是为了提高模型的表现</li>
</ul>
</li>
</ul>
<h3 id="行为健康度"><a href="#行为健康度" class="headerlink" title="行为健康度"></a>行为健康度</h3><ul>
<li><p>Label：根据乘客在历史X个月的行为表现预测在未来X个月的行为表现。好：label=0，坏：label=1.（其中历史x选取6，未来x选取1）</p>
<p>其中坏行为是有责投诉(费用类有责投诉和服务类有责投诉)、有责取消和迟到。</p>
<p><strong>label选取方式：</strong></p>
<ol>
<li>人群范围：历史六个月发单&gt;=10单 &amp; 未来一个月发单&gt;=5单</li>
<li>label1：未来一个月的坏行为发生率&gt;=0.4，其中坏行为发生率=（有责投诉数+有责取消数+迟到）/ 发单数。</li>
<li>label0：未来一个月的坏行为发生次数&lt;=1</li>
</ol>
</li>
<li><p>数据选取：</p>
<ol>
<li>label1：选取满足条件的全部数据量。</li>
<li>label0：从满足条件的数据中随机选取14w。正：负=1：1。</li>
<li>数据划分：训练集：测试集=8:2</li>
</ol>
</li>
<li><p>特征：[快专出豪顺]完单数、投诉数、费用有责投诉、服务类有责投诉（不包括取消和费用投诉）、有责取消次数、无责取消次数、应答后取消次数、对司机好评、差评、迟到…</p>
</li>
<li><p>评估：</p>
<ul>
<li>虚假投诉乘客管控：高投诉高补偿（发单&gt;=10 &amp; 投诉工单&gt;=5 &amp;（投诉率&gt;=0.3 or 投诉数&gt;= 15） &amp; (补偿率&gt;= 0.3 or 补偿订单数&gt;= 10) &amp; 用户价值&lt;0 ）乘客分布集中在低分段</li>
</ul>
</li>
<li><p>应用：</p>
<ul>
<li>区域乘客教育：取消、迟到、投诉、费用投诉、费用有责投诉的分布、与分数的分布、率的分布。最终使用规则+分数的方式做乘客教育。其中规则和分数的阈值选取：考虑影响面（8万左右）。取消次数大于等于3次，分数小于等于620分，对应人数80934，作为教育的对象；迟到次数大于等于3次，分数小于等于569，影响人数19239，作为教育的对象。<strong>高取消/高迟到乘客次月的重犯次数依旧很高，说明教育必要性</strong></li>
<li>乘客管控：石锤虚假投诉封禁</li>
</ul>
</li>
</ul>
<h3 id="分数更新"><a href="#分数更新" class="headerlink" title="分数更新"></a>分数更新</h3><ol>
<li>更新方式<ol>
<li>全量更新：选取固定时间周期，滑动窗口，重新训练模型。<ol>
<li>优势：模型是用最新的数据产生的模型，产生的分数在固定维度内具有区分度。</li>
<li>劣势：每次生成新的分数，分数变动不稳定。</li>
</ol>
</li>
<li>增量更新：在初始分数的基础上，根据增量的数据做分数的增量变动。<ol>
<li>优势：分数变动波动性小。</li>
<li>劣势：增量分数的累积会使区分度变差。</li>
</ol>
</li>
</ol>
</li>
<li>更新周期<ol>
<li>参考选取label的周期。label选取是未来一个月，更新周期是一个月更新一次。</li>
<li>更新周期太频繁，分数变动太快，不够稳定。更新周期太长，分数不够准确体现乘客当前的行为。</li>
</ol>
</li>
</ol>
<p>为了使模型向后兼容&amp;&amp;打通流程，在更新时选取增量更新的方式，初试分数的计算和增量更新时的分数需要具有可解释性。</p>
<h2 id="问题与挑战"><a href="#问题与挑战" class="headerlink" title="问题与挑战"></a>问题与挑战</h2><h3 id="多个业务场景"><a href="#多个业务场景" class="headerlink" title="多个业务场景"></a>多个业务场景</h3><p>分多维度、维度下分子维度，不同维度与子维度都会生成相应的分数，对不同维度设置不同阈值，从而建立个性化的门槛，就可以赋能于不同的业务场景（<strong>用户权益／乘客管控／司机体验</strong>）。</p>
<h3 id="可解释性"><a href="#可解释性" class="headerlink" title="可解释性"></a>可解释性</h3><p>乘客行为分在最终理想态下需要透传。这意味着，需要考虑行为分（加分和扣分）的可解释性。对用户透传分数时有以下几种不同的力度和方案。</p>
<ol>
<li>直接透传当前的总分（类似芝麻分）。这种形式可控性强，但用户对于自己的分数怎么计算的会有疑惑，透传的话会有大量的用户进线。</li>
<li>透传每种行为项的分数。<ul>
<li>这种形式可解释性强，用户对于分数的构成很清晰，但是会造成用户恶意刷分的情况。同时不在计算范围的行为，用户可能不会care，从而缺乏管控的能力。</li>
<li>这种形式可控性很差。如果后期每项行为的分值发生变化，分数的稳定性会受到用户的质疑。</li>
</ul>
</li>
</ol>
<ol>
<li>两种形式的折衷（类似内测的橙信值）。对于坏行为给用户完全透传出来，使用户意识到哪些形式要明令禁止的；对于好行为给出加分的总和。</li>
<li>两种形式的折衷（类似内测的橙信值）。对于坏行为给用户完全透传出来，使用户意识到哪些形式要明令禁止的；对于好行为给出加分的总和。</li>
</ol>
<p>增强行为分可解释性，意味着牺牲策略空间，并且增加了刷分的风险。所以在一些维度（例如乘客身份特征：如实名认证等）上需要尽可能提供高可解释性，而在另一些维度（例如行为健康度：如被司机投诉等）上则需要尽可能保持高度灵活。</p>
<p><strong><em>xgboost更具解释性？存疑 每个叶子都有权重</em></strong></p>
<h3 id="数据稀疏"><a href="#数据稀疏" class="headerlink" title="数据稀疏"></a>数据稀疏</h3><ul>
<li>采样方式，解决有些特征难以用到的问题</li>
</ul>
<p>调研了推荐系统中的数据稀疏解决方式，见wiki</p>
<p>两篇论文：</p>
<p><a href="http://link.zhihu.com/?target=https%3A//github.com/wzhe06/Reco-papers/blob/master/Embedding/%5BAirbnb%20Embedding%5D%20Real-time%20Personalization%20using%20Embeddings%20for%20Search%20Ranking%20at%20Airbnb%20%28Airbnb%202018%29.pdf" target="_blank" rel="noopener">Real-time Personalization using Embeddings for Search Ranking at Airbnb (Airbnb 2018)</a></p>
<p><a href="http://link.zhihu.com/?target=https%3A//github.com/wzhe06/Reco-papers/blob/master/Embedding/%5BAlibaba%20Embedding%5D%20Billion-scale%20Commodity%20Embedding%20for%20E-commerce%20Recommendation%20in%20Alibaba%20%28Alibaba%202018%29.pdf" target="_blank" rel="noopener">[Alibaba Embedding] Billion-scale Commodity Embedding for E-commerce Recommendation in Alibaba (Alibaba 2018)</a></p>
<h2 id="体会"><a href="#体会" class="headerlink" title="体会"></a>体会</h2><ul>
<li><p>数据：自己取；大规模；</p>
</li>
<li><p>建模目标、label：自定义</p>
</li>
<li><p>问题：采样方法、数据稀疏</p>
</li>
<li><p>Q：在一个具体项目中，前期通过简单的规则作为baseline的必要性在哪？</p>
<p>A：1）前期实现时，模型缺乏对照，规则是最简单的可以提供此对照的实现；</p>
<p>2）公司中不仅有算法/策略部门，还有产品、运营、开发部门，为什么产品、运营、开发给一份规则不能解决问题？算法相对规则可以带来多少delta收益？这也是方案评估的时候会被考虑的几个标准，换言之，baseline作为对照也是对算法/策略部门存在必要性的一个说明。</p>
<p>Q：机器学习模型中，有些标签本身就是离散的，例如男/女，有房/无房等，而有些标签是连续特征离散化的，例如青年/中年，再例如判责中有有责/无责，也有判不清，这些标签是人为从某些连续标签经过离散化得到的。在拟合连续标签离散化得到的标签的时候，就存在一个灰色样本的问题：人为设定的界线附近的标签区分度不高（例如长得很像狗的猫和长得很像猫的狗就很难给出区分的定义），导致在训练集中打label的时候很难打；就算打好了label，预测时灰色样本的置信度也会比较低，这该如何解决？</p>
<p>A：1）二分类问题模型输出是一个概率值，再通过设置阈值的方式可以规避掉这些灰色样本的存在，但这种方法是回避了问题，并没有真正判清样本；2）有些分类模型是通过设置阈值来分类的，也有些是通过排序来分类，应用排序的方式可以避免概率值接近这种衡量方式上的判不清；3）有些连续标签的离散化相当于模糊集合的应用，因此在模型中恰当地引入模糊集合理论也可以实现对问题的解决。</p>
<p>A2：工业界中的数据是自己产生的，label有时是真实数据，有时是要自己打的，信用分三个子维度的问题，是通过已有数据打label，这个打的过程本身就存在打不清楚的问题；如果在训练集中剔除灰色样本，则—-→训练集测试集分布不一致，用不存在预测存在，出现很多问题。</p>
<p>泓州提到，分布要一致这玩意是理论，我们现在在实践，实践以实际业务需求以及效果为衡量王道，其他不care，能否满足业务需求，能否达到更好的效果才是所关心的，所以分布一致这条原则可以舍去。</p>
<p>感想：没那么多条条框框，思维要开阔，限制不应该是理论前提的不满足，而是业务、效果。？业务、效果也别限制了吧，怎么爽怎么来。</p>
<p><img src="C:\Users\Chenzk\Documents\Learning\滴滴\cmd\image\微信图片_20191115101713.png" alt="微信图片_20191115101713"></p>
</li>
<li><p>业务方：模型的本质是用历史行为来判责当次发生的问题，说服力不强。</p>
<p>业务方要求定制化分数?</p>
<p>可解释性？</p>
<p>Q：为什么要有可解释性，对这个分数负责不就好了，用户真的有申诉信用分的必要吗？</p>
<p>A：权益激励/限制权益等不需要，类似于芝麻分信用分不够不能免费骑车也不会有人申诉。但是一些更大的处置动作，例如准出、处罚等需要有可解释性。不care前85%的好人好在哪里，关注的是尾部分布的15%有问题的乘客问题在哪里，以及问题会导致什么 ——&gt; 管控</p>
</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/贪心算法/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/贪心算法/" itemprop="url">贪心算法</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <h4 id="贪心算法"><a href="#贪心算法" class="headerlink" title="贪心算法"></a>贪心算法</h4><p>顾名思义，贪心算法总是作出在当前看来最好的选择。也就是说贪心算法并不从整体最优考虑，它所作出的选择只是在某种意义上的局部最优选择。在一些情况下，即使贪心算法不能得到整体最优解，其最终结果却是最优解的很好近似。</p>
<ul>
<li><p>贪心选择性质。所谓贪心选择性质是指所求问题的整体最优解可以通过一系列局部最优的选择，即贪心选择来达到。这是贪心算法可行的第一个基本要素，也是贪心算法与动态规划算法的主要区别。</p>
<p>动态规划算法通常以自底向上的方式解各子问题，而贪心算法则通常以自顶向下的方式进行，以迭代的方式作出相继的贪心选择，每作一次贪心选择就将所求问题简化为规模更小的子问题。</p>
<p>对于一个具体问题，要确定它是否具有贪心选择性质，必须证明每一步所作的贪心选择最终导致问题的整体最优解。</p>
</li>
<li><p>当一个问题的最优解包含其子问题的最优解时，称此问题具有最优子结构性质。问题的最优子结构性质是该问题可用动态规划算法或贪心算法求解的关键特征。</p>
</li>
</ul>
<h4 id="活动时间安排"><a href="#活动时间安排" class="headerlink" title="活动时间安排"></a>活动时间安排</h4><p>设有N个活动时间集合，每个活动都要使用同一个资源，比如说会议场，而且同一时间内只能有一个活动使用，每个活动都有一个使用活动的开始si和结束时间fi，即他的使用区间为（si,fi）,现在要求你分配活动占用时间表，即哪些活动占用该会议室，哪些不占用，使得他们不冲突，要求是尽可能多的使参加的活动最大化，即所占时间区间最大化。</p>
<p><img src="https://img-my.csdn.net/uploads/201303/29/1364554174_8902.jpg" alt="img"></p>
<ul>
<li>重点：<strong>结束时间按顺序排列</strong>。时间从前往后推移，若以当时时间为开始时间的活动的开始时间≥前一个活动的结束时间，选择此活动即可 –&gt; 原因是<strong>结束时间按顺序排列</strong>。</li>
</ul>
<figure class="highlight plain"><figcaption><span>main(int argc, char* argv[])</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">int main(int argc,char* argv[])</span><br><span class="line">&#123;</span><br><span class="line">	int s[11] =&#123;1,3,0,5,3,5,6,8,8,2,12&#125;;</span><br><span class="line">	int f[11] =&#123;4,5,6,7,8,9,10,11,12,13,14&#125;;</span><br><span class="line"> </span><br><span class="line">	bool mark[11] = &#123;0&#125;;</span><br><span class="line"> </span><br><span class="line">	GreedyChoose(11,s,f,mark);</span><br><span class="line">	for(int i=0;i&lt;11;i++)</span><br><span class="line">		if(mark[i])</span><br><span class="line">			cout&lt;&lt;i&lt;&lt;&quot; &quot;;</span><br><span class="line">	system(&quot;pause&quot;);</span><br><span class="line">	return 0;</span><br><span class="line">&#125;</span><br><span class="line"> </span><br><span class="line">void GreedyChoose(int len,int *s,int *f,bool *flag)</span><br><span class="line">&#123;</span><br><span class="line">	flag[0] = true;</span><br><span class="line">	int j = 0;</span><br><span class="line">	for(int i=1;i&lt;len;++i)</span><br><span class="line">		if(s[i] &gt;= f[j])</span><br><span class="line">		&#123;</span><br><span class="line">			flag[i] = true;</span><br><span class="line">			j = i;</span><br><span class="line">		&#125;</span><br></pre></td></tr></table></figure>
<h4 id="线段覆盖"><a href="#线段覆盖" class="headerlink" title="线段覆盖"></a>线段覆盖</h4><p>在一维空间中告诉你N条线段的起始坐标与终止坐标，要求求出这些线段一共覆盖了多大的长度。</p>
<p><img src="https://img-my.csdn.net/uploads/201303/30/1364630415_9404.jpg" alt="img"></p>
<p>重点：<strong>将线段按起始坐标排序</strong>。</p>
<figure class="highlight plain"><figcaption><span>main(int argc, char* argv[])</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">	int s[10] = &#123;2,3,4,5,6,7,8,9,10,11&#125;;</span><br><span class="line">	int f[10] = &#123;3,5,7,6,9,8,12,10,13,15&#125;;</span><br><span class="line">	int TotalLength = (3-2);                 </span><br><span class="line"> </span><br><span class="line">	for(int i=1,int j=0; i&lt;10 ; ++i)</span><br><span class="line">	&#123;</span><br><span class="line">		if(s[i] &gt;= f[j])</span><br><span class="line">		&#123;</span><br><span class="line">			TotalLength += (f[i]-s[i]);</span><br><span class="line">			j = i;</span><br><span class="line">		&#125;</span><br><span class="line">		else</span><br><span class="line">		&#123;</span><br><span class="line">			if(f[i] &lt;= f[j])</span><br><span class="line">				continue;</span><br><span class="line">			else</span><br><span class="line">			&#123;</span><br><span class="line">				TotalLength += f[i] - f[j];</span><br><span class="line">				j = i;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line"> </span><br><span class="line">	cout&lt;&lt;TotalLength&lt;&lt;endl;</span><br><span class="line">	system(&quot;pause&quot;);</span><br><span class="line">	return 0;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="找零钱问题"><a href="#找零钱问题" class="headerlink" title="找零钱问题"></a>找零钱问题</h4><p>贪心：每次选择可选的最大面值的钱。</p>
<p>本质上还是<strong>排序</strong>。</p>
<h4 id="Leetcode"><a href="#Leetcode" class="headerlink" title="Leetcode:"></a>Leetcode:</h4><p>给定一个数组，它的第 <em>i</em> 个元素是一支给定股票第 <em>i</em> 天的价格。</p>
<p>设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易（多次买卖一支股票）。</p>
<p><strong>注意：</strong>你不能同时参与多笔交易（你必须在再次购买前出售掉之前的股票）。</p>
<p><a href="https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/1/array/22/" target="_blank" rel="noopener">https://leetcode-cn.com/explore/interview/card/top-interview-questions-easy/1/array/22/</a></p>
<p>使用贪心算法的一个假设：同一天可以卖出又可以买入</p>
<figure class="highlight plain"><figcaption><span>Solution</span></figcaption><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">def maxProfit(self, prices: List[int]) -&gt; int:</span><br><span class="line">    ans = 0</span><br><span class="line">    for i in range(len(prices)-1):</span><br><span class="line">        if prices[i+1]&gt;prices[i]:</span><br><span class="line">            ans += prices[i+1]-prices[i]</span><br><span class="line">    return ans</span><br></pre></td></tr></table></figure>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/评分卡优化/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/评分卡优化/" itemprop="url">评分卡优化</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ul>
<li>A-Bln(odds)：应有weight&gt;0</li>
</ul>
<h1 id="优化1"><a href="#优化1" class="headerlink" title="优化1"></a>优化1</h1><ul>
<li>加入更多的网约车数据</li>
<li>等宽</li>
<li>删特征 –&gt; weight&lt;0的特征减少了 –&gt;平滑 </li>
<li>异常值处理：做异常值截断</li>
<li>长尾分布取对数</li>
</ul>
<ul>
<li>只用ygc数据，且进行上采样，precision不超过5% –&gt; 无效果</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
      

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chenzk1.github.io/2019/11/19/评分卡/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Hero">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Hero's notebooks">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
                
                <a class="post-title-link" href="/2019/11/19/评分卡/" itemprop="url">评分卡</a></h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-11-19T10:23:10+08:00">
                2019-11-19
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">In</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Learning/" itemprop="url" rel="index">
                    <span itemprop="name">Learning</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        
          
            <ul>
<li><p>模型流程</p>
<ul>
<li><p>分箱：等频、等距、卡方（掌握卡方分箱的原理和操作方式：卡方值最小的相邻区间合并（卡方越小说明俩区间区别越小，卡方衡量都是区间中label的分布））</p>
</li>
<li><p>根据分箱求得woe=ln(# good占比/ # bad占比)</p>
</li>
<li><p>LR模型获得W</p>
</li>
<li><p>score = A - B*ln(odds) </p>
<ul>
<li>直观理解：对一条数据来说，其属于好样本的概率与属于坏样本的概率的比值越大，其分数越大。只不过用了LR来间接表示这个概率，且未直接用到特征值，用到的是对label有可解释性的woe值。</li>
<li>A, B: 设置比率为θ0（也就是odds）的特定点分值为P0，比率为2θ0的点的分值为P0+PDO。带入上面公式可得到：</li>
</ul>
<p>$$<br>\left{\begin{array}{ll}{P_{0}} &amp; {=A-B \ln \left(\theta_{0}\right)} \ {P_{0}+P D O} &amp; {=A-\operatorname{Bln}\left(2 \theta_{0}\right)}\end{array}\right.<br>$$</p>
<p>即：<br>$$<br>\left{\begin{array}{l}{B=\frac{P D O}{l n 2}} \ {A=P_{0}+B \ln \left(\theta_{0}\right)}\end{array}\right.<br>$$</p>
</li>
</ul>
</li>
</ul>
<pre><code>（可以设置P0=600，PDO=20, θ0=1/30）
</code></pre><ul>
<li><p>实际应用时</p>
<ul>
<li>LR模型中：</li>
</ul>
<p>$$<br>p=\frac{1}{1+e^{-\theta^{T} x}}<br>$$</p>
<p>$$<br>\begin{array}{c}{\ln \left(\frac{p}{1-p}\right)=\theta^{T} x} \ {\ln \left(\frac{p}{1-p}\right)=\ln (\text {odds})} \ {\ln (\text {odds})=\theta^{T} x=w_{0}+w_{1} x_{1}+\cdots+w_{n} x_{n}}\end{array}<br>$$</p>
<p>$$<br>\begin{aligned} \text {score}<em>{\mathbb{Z}} &amp;=A+B <em>\left(\theta^{T} x\right)=A+B </em>\left(w</em>{0}+w_{1} x_{1}+\cdots+w_{n} x_{n}\right) \ &amp;=\left(A+B <em> w_{0}\right)+B </em> w_{1} x_{1}+\cdots+B * w_{n} x_{n} \end{aligned}<br>$$</p>
</li>
</ul>
<pre><code>先通过lr模型对(woe, label)训练得到权重矩阵，并获得初始分A+B*w0；每个变量的分箱对应的分数为，权重\*每个分箱对应的woe

- 新加入的用户，根据之前得到的分箱dict得到其特征的分箱区间对其特征进行分箱，在根据上一步得到的每个分箱的分数来获得每个特征的分数，并逐个相加，得到总分数
</code></pre><ul>
<li><p>特征选择与分箱调参</p>
<ul>
<li><p><strong>并不是维度越多越好。</strong>一个评分卡中，一般不超过15个维度。</p>
<ol>
<li>可根据Logistic Regression模型系数来确定每个变量的权重，保留权重高的变量。通过协方差计算的相关性大于0.7的变量一般只保留IV值最高的那一个。</li>
<li>IV可以衡量特征的预测能力：</li>
</ol>
<p>$$<br>I V=\sum_{i=1}^{N}\left(g o o d_{占比} -bad_{占比} \right) * W O E_{i}<br>$$</p>
</li>
</ul>
<p>| IV        | 预测能力   |<br>| ——— | ———- |<br>| &lt;0.03     | 无预测能力 |<br>| 0.03~0.09 | 低         |<br>| 0.1~0.29  | 中         |<br>| 0.3~0.49  | 高         |<br>| &gt;=0.5     | 极高       |</p>
<p>预测能力低则需重新调整分箱。</p>
</li>
</ul>

          
        
      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      

      

      
      
        <div class="post-eof"></div>
      
    </footer>
  </div>
  
  
  
  </article>


    
  </section>

  
  <nav class="pagination">
    <span class="page-number current">1</span><a class="page-number" href="/page/2/">2</a><span class="space">&hellip;</span><a class="page-number" href="/page/5/">5</a><a class="extend next" rel="next" href="/page/2/"><i class="fa fa-angle-right"></i></a>
  </nav>



          </div>
          


          

        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview sidebar-panel sidebar-panel-active">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image" src="/images/avatar.jpg" alt="Hero">
          <p class="site-author-name" itemprop="name">Hero</p>
           
              <p class="site-description motion-element" itemprop="description">hero's notebooks</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives/">
                <span class="site-state-item-count">47</span>
                <span class="site-state-item-name">posts</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">1</span>
                <span class="site-state-item-name">categories</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">26</span>
                <span class="site-state-item-name">tags</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Hero</span>
</div>


<div class="powered-by">
  Powered by <a class="theme-link" href="https://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  
    <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>

  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  






  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  

  

  

</body>
</html>
